// 行秋极限解析
// 90级面板
// 白值:202, 暴击率:5, 暴击伤害:50, 攻击加成: 24

// 命座效果  大招命中降低15水抗 大招后e伤害x1.5 满命每三次大招发射的剑数量增加且回能量

// 行秋大招 不同人 不同环境触发不稳定 
// !!!这里取5次蒸发 30次不蒸发  e取第一段蒸发 的总伤害来当作参考

// 腐蚀 510  45.6充能 e增伤32 12暴击
// 宗室+水   攻击 水伤 暴击  副词: 暴击 35.1(9)  爆伤 124.8(16) 
// 攻击  1710   充能45.6   暴击86.8 爆伤213.8
// 增伤 46.6水杯  20天赋水伤 15水套 e额外32
// e 56450    e蒸发第一段 94034   e双蒸发 136845
// q 4929   q蒸发 11948
// 总 301650

// 祭礼 454  61.3充能  80%几率刷新e 充能更强大!!!
// 宗室+水   攻击 水伤 暴击  副词: 暴击 46.8(12)  爆伤 101.4(13)
// 攻击  1601   充能61.3  暴击98.5  爆伤190.4
// 增伤 46.6水杯  20天赋水伤 15水套
// e 41525    e蒸发第一段 69173   e双蒸发 100665
// q 4647   q蒸发 11267
// 总 320288 (这里考虑到了e80%几率刷新)

// 天空 608 8暴击 55.1充能
// 宗室+水   攻击 水伤 暴击  副词: 暴击 39(10)  爆伤 117(15) 
// 攻击  1900   充能55.1  暴击98.7 爆伤206
// 增伤 46.6水杯  20天赋水伤 15水套 
// e 51968    e蒸发第一段 86568   e双蒸发 125980
// q 4929   q蒸发 11948
// 总 331578


// 宇宙第一黎明神剑 401 28暴击(不能掉血到90%以下) 46.9爆伤
// 宗室+水   攻击 水伤 暴击  副词:攻击23.2 暴击 19.5  爆伤 124.8
// 攻击  1638    暴击99.2 爆伤260.7
// 增伤 46.6水杯  20天赋水伤 15水套 
// e 52992    e蒸发第一段 88273   e双蒸发 128461
// q 5931   q蒸发 14378
// 总 338108

// 匣里龙吟(渡火套) 510 41.3攻击 敌人处于火雷附着下36增伤 渡火35   敌人挂火打蒸发触发71增伤
// 渡火  攻击 水伤 暴击  副词: 暴击 46.8(12)  爆伤 101.4(13)
// 攻击  2003     暴击98.5  爆伤190.4
// 增伤 46.6水杯  20天赋水伤 15水套 
// e 47673(不打蒸发没伤害)   e蒸发第一段 113257   e双蒸发 164820
// q 5383   q蒸发 18016
// 总 364854

// 宗室长剑 510  41.3攻击 技能特效难以计算 这里以16常驻暴击当参考  不推荐 成本太贵 
// 宗室+水   攻击 水伤 爆伤  副词:  暴击 58.5  爆伤 78
// 攻击  2003    暴击99 爆伤221.4
// 增伤 46.6水杯  20天赋水伤 15水套 
// e 57684    e蒸发第一段 96089   e双蒸发 139836
// q 6456   q蒸发 15651
// 总 368045

// 盾剑 后台难以触发 这里就当常驻的20攻击计算了
// 608    46.9 + 20 攻击
// 宗室+水   攻击 水伤 爆击  副词:  暴击 46.8(12)  爆伤 101.4(13)
// 攻击  2441    暴击98.5 爆伤190.4
// 增伤 46.6水杯  20天赋水伤 15水套 
// e 63317    e蒸发第一段 105473   e双蒸发 153493
// q 7087   q蒸发 17180
// 总 403989









let charaters = {
    xq : {
        name: "lv90行秋", 
        base: 202,
        attRate: 24,
        dmgRate: 20,
        criticalRate: 5,
        criticalStrike: 50
    }
}

let weapons = {
    lm: {
        name:"lv90黎明", 
        base: 401,  
        criticalStrike: 46.9,
        criticalRate:28
    },
    fs: {
        name:"lv90腐蚀",  // e技能获得32增伤  12暴击
        base: 510,
        "充能": 45.9
    },
    xl: {
        name:"lv90匣里龙吟",  // 敌人火雷元素附着下增伤36
        base: 510,
        attRate: 41.3
    },
    jl: {
        name:"lv90祭礼",  // 80%几率刷新e 
        base: 454,
        "充能":61.3
    },
    zs: {
        name:"lv90宗室",  // 造成伤害提高暴击  16% 叠加5次 叠加满后移除  这里难以计算 只能以常驻的暴击率估算 取24
        base: 510,
        criticalRate:16,
        attRate: 41.3
    },
    tk: {
        name:"lv90天空",  // 
        base: 608,
        criticalRate:8,
        "充能": 55.1
    },
    zf: {
        name:"lv90盾剑",  // 
        base: 608,
        attRate:46.9 + 20
    }
}
let normal_clips = calc_clips_normal();
let normal_clips2 = calc_clips_normal(2);
let charactersDmg = []

// 行秋 黎明 宗室+水
charactersDmg.push(getDMG([charaters.xq,weapons.lm,{fixedAtt:311,criticalRate:31.1,dmgRate:46.6,attRate:46.6},normal_clips], (data,second) => {
    // 宗室套+水 大招20增伤  15水伤
    data.dmgRate += 15;
    let attack = data.base *(1 + data.attRate/100) + data.fixedAtt
    let rea = { 精通:data.精通, 系数:2, 精通增伤:0 }
    
    let eDmg = getDmgDps(data, 3.02+3.44) * q(-5) * df(90,90) * 1.5;
    let eDmgRea = getDmgDps(data, 3.02+3.44,rea) * q(-5) * df(90,90) * 1.5;
    let eDmgRea1 = getDmgDps(data, 3.02,rea) * q(-5) * df(90,90) * 1.5 + getDmgDps(data, 3.44) * q(-5) * df(90,90) * 1.5;
    
    let qRea = getDmgDps({...data, dmgRate:data.dmgRate+20}, 0.977, rea) * q(-5) * df(90,90);
    let qd = getDmgDps({...data, dmgRate:data.dmgRate+20}, 0.977) * q(-5) * df(90,90);
    
    let ret = qRea*5 + qd*30 + eDmgRea1
    return {point:ret, data, second, attack, qRea, qd,eDmg,eDmgRea,eDmgRea1 }
}))

// 行秋 天空 宗室+水
charactersDmg.push(getDMG([charaters.xq,weapons.tk,{fixedAtt:311,criticalRate:31.1,dmgRate:46.6,attRate:46.6},normal_clips], (data,second) => {
   // 宗室套+水 大招20增伤  15水伤
   data.dmgRate += 15;
   let attack = data.base *(1 + data.attRate/100) + data.fixedAtt
   let rea = { 精通:data.精通, 系数:2, 精通增伤:0 }
   
   let eDmg = getDmgDps(data, 3.02+3.44) * q(-5) * df(90,90) * 1.5;
   let eDmgRea = getDmgDps(data, 3.02+3.44,rea) * q(-5) * df(90,90) * 1.5;
   let eDmgRea1 = getDmgDps(data, 3.02,rea) * q(-5) * df(90,90) * 1.5 + getDmgDps(data, 3.44) * q(-5) * df(90,90) * 1.5;
   
   let qRea = getDmgDps({...data, dmgRate:data.dmgRate+20}, 0.977, rea) * q(-5) * df(90,90);
   let qd = getDmgDps({...data, dmgRate:data.dmgRate+20}, 0.977) * q(-5) * df(90,90);
   
   let ret = qRea*5 + qd*30 + eDmgRea1
   return {point:ret, data, second, attack, qRea, qd,eDmg,eDmgRea,eDmgRea1 }
}))

// 行秋 盾剑 宗室+水
charactersDmg.push(getDMG([charaters.xq,weapons.zf,{fixedAtt:311,criticalRate:31.1,dmgRate:46.6,attRate:46.6},normal_clips], (data,second) => {
    // 宗室套+水 大招20增伤  15水伤
    data.dmgRate += 15;
    let attack = data.base *(1 + data.attRate/100) + data.fixedAtt
    let rea = { 精通:data.精通, 系数:2, 精通增伤:0 }
    
    let eDmg = getDmgDps(data, 3.02+3.44) * q(-5) * df(90,90) * 1.5;
    let eDmgRea = getDmgDps(data, 3.02+3.44,rea) * q(-5) * df(90,90) * 1.5;
    let eDmgRea1 = getDmgDps(data, 3.02,rea) * q(-5) * df(90,90) * 1.5 + getDmgDps(data, 3.44) * q(-5) * df(90,90) * 1.5;
    
    let qRea = getDmgDps({...data, dmgRate:data.dmgRate+20}, 0.977, rea) * q(-5) * df(90,90);
    let qd = getDmgDps({...data, dmgRate:data.dmgRate+20}, 0.977) * q(-5) * df(90,90);
    
    let ret = qRea*5 + qd*30 + eDmgRea1
    return {point:ret, data, second, attack, qRea, qd,eDmg,eDmgRea,eDmgRea1 }
}))

// 行秋 祭礼 宗室+水
charactersDmg.push(getDMG([charaters.xq,weapons.jl,{fixedAtt:311,criticalRate:31.1,dmgRate:46.6,attRate:46.6},normal_clips], (data,second) => {
    // 宗室套+水 大招20增伤  15水伤
    data.dmgRate += 15;
    let attack = data.base *(1 + data.attRate/100) + data.fixedAtt
    let rea = { 精通:data.精通, 系数:2, 精通增伤:0 }
    
    let eDmg = getDmgDps(data, 3.02+3.44) * q(-5) * df(90,90) * 1.5;
    let eDmgRea = getDmgDps(data, 3.02+3.44,rea) * q(-5) * df(90,90) * 1.5;
    let eDmgRea1 = getDmgDps(data, 3.02,rea) * q(-5) * df(90,90) * 1.5 + getDmgDps(data, 3.44) * q(-5) * df(90,90) * 1.5;
    
    let qRea = getDmgDps({...data, dmgRate:data.dmgRate+20}, 0.977, rea) * q(-5) * df(90,90);
    let qd = getDmgDps({...data, dmgRate:data.dmgRate+20}, 0.977) * q(-5) * df(90,90);
    
    let ret = qRea*5 + qd*30 + eDmgRea1*1.8
    return {point:ret, data, second, attack, qRea, qd,eDmg,eDmgRea,eDmgRea1 }
}))


// 行秋 宗室 宗室+水
charactersDmg.push(getDMG([charaters.xq,weapons.zs,{fixedAtt:311,criticalStrike:62.2,dmgRate:46.6,attRate:46.6},normal_clips2], (data,second) => {
    // 宗室套+水 大招20增伤  15水伤
    data.dmgRate += 15;
    let attack = data.base *(1 + data.attRate/100) + data.fixedAtt
    let rea = { 精通:data.精通, 系数:2, 精通增伤:0 }
    
    let eDmg = getDmgDps(data, 3.02+3.44) * q(-5) * df(90,90) * 1.5;
    let eDmgRea = getDmgDps(data, 3.02+3.44,rea) * q(-5) * df(90,90) * 1.5;
    let eDmgRea1 = getDmgDps(data, 3.02,rea) * q(-5) * df(90,90) * 1.5 + getDmgDps(data, 3.44) * q(-5) * df(90,90) * 1.5;
    
    let qRea = getDmgDps({...data, dmgRate:data.dmgRate+20}, 0.977, rea) * q(-5) * df(90,90);
    let qd = getDmgDps({...data, dmgRate:data.dmgRate+20}, 0.977) * q(-5) * df(90,90);
    
    let ret = qRea*5 + qd*30 + eDmgRea1
    return {point:ret, data, second, attack, qRea, qd,eDmg,eDmgRea,eDmgRea1 }
}))

// 行秋 匣里 渡火
charactersDmg.push(getDMG([charaters.xq,weapons.xl,{fixedAtt:311,criticalRate:31.1,dmgRate:46.6,attRate:46.6},normal_clips], (data,second) => {
    // 敌人火附着时候 增伤 71
    let attack = data.base *(1 + data.attRate/100) + data.fixedAtt
    let rea = { 精通:data.精通, 系数:2, 精通增伤:0 }
    
    let eDmg = getDmgDps(data, 3.02+3.44) * q(-5) * df(90,90) * 1.5;
    let qd = getDmgDps({...data, dmgRate:data.dmgRate+20}, 0.977) * q(-5) * df(90,90);
    data.dmgRate += 71;
    let eDmgRea = getDmgDps(data, 3.02+3.44,rea) * q(-5) * df(90,90) * 1.5;
    let eDmgRea1 = getDmgDps(data, 3.02,rea) * q(-5) * df(90,90) * 1.5 + getDmgDps(data, 3.44) * q(-5) * df(90,90) * 1.5;
    let qRea = getDmgDps({...data, dmgRate:data.dmgRate+20}, 0.977, rea) * q(-5) * df(90,90);
    
    let ret = qRea*5 + qd*30 + eDmgRea1
    return {point:ret, data, second, attack, qRea, qd,eDmg,eDmgRea,eDmgRea1 }
}))

// 行秋 腐蚀 宗室+水
charactersDmg.push(getDMG([charaters.xq,weapons.fs,{fixedAtt:311,criticalRate:31.1,dmgRate:46.6,attRate:46.6},normal_clips], (data,second) => {
    // 宗室套+水 大招20增伤  15水伤
    data.dmgRate += 15;
    data.criticalRate += 12;
    let attack = data.base *(1 + data.attRate/100) + data.fixedAtt
    let rea = { 精通:data.精通, 系数:2, 精通增伤:0 }
    
    let eDmg = getDmgDps({...data, dmgRate:data.dmgRate+32}, 3.02+3.44) * q(-5) * df(90,90) * 1.5;
    let eDmgRea = getDmgDps({...data, dmgRate:data.dmgRate+32}, 3.02+3.44,rea) * q(-5) * df(90,90) * 1.5;
    let eDmgRea1 = getDmgDps({...data, dmgRate:data.dmgRate+32}, 3.02,rea) * q(-5) * df(90,90) * 1.5 + getDmgDps({...data, dmgRate:data.dmgRate+32}, 3.44) * q(-5) * df(90,90) * 1.5;
    
    data.criticalRate -= 12;
    let qRea = getDmgDps({...data, dmgRate:data.dmgRate+20}, 0.977, rea) * q(-5) * df(90,90);
    let qd = getDmgDps({...data, dmgRate:data.dmgRate+20}, 0.977) * q(-5) * df(90,90);
    
    let ret = qRea*5 + qd*30 + eDmgRea1
    return {point:ret, data, second, attack, qRea, qd,eDmg,eDmgRea,eDmgRea1 }
}))

console.log(charactersDmg.sort((a,b)=>b.point-a.point));



function getDMG(dataarr, getRet){
    let chance = 25;
    let _ret = [];
    for (let index = 0; index <= chance; index++) {
        let criticalStrike = index; 
        for (let index2 = 0; index2 <= chance - index; index2++) {
            let criticalRate = index2;
            for (let index3 = 0; index3 <= chance-index-index2; index3++) {
                let attRate = index3;
                let defenceRate = chance - index - index2 - index3;
                _ret.push({
                    精通: 23 * defenceRate,
                    attRate:5.8 * attRate,
                    criticalRate:3.9 * criticalRate,
                    criticalStrike:7.8 * criticalStrike
                });
            }
        }
    }
    _ret = _ret.map(second => {
        let panel = getPanel([...dataarr, second]);
        return  getRet(panel, second)
    })
    _ret.sort((b,a)=> a.point-b.point)
    return _ret[0]
}

function getDmgDps(data, rate=1, rea){
    let criticalRate = data.criticalRate
    if(criticalRate > 100){criticalRate = 100}
    let baseat = data.base * (1 + data.attRate/100) + data.fixedAtt;
    let bdmg = baseat * (1 + data.criticalStrike/100);
    let bdps = (criticalRate * 10 * bdmg + (1000-criticalRate * 10)*baseat)/1000
    let adddmg = bdps * (1 + data.dmgRate/100)
    if(rea){
        let {精通, 系数, 精通增伤} = rea
        let tmp = 1 + 精通增伤 + jt(精通);
        return adddmg * rate * 系数 * tmp
    }
    return adddmg * rate
}

function getPanel(arr){
    let info = {name1:"",name2:""};
    arr.forEach((item, i)=>{
        if(item.name){
            info["name" + (i+1)] = item.name
        }
        for (const key in item) {
            if(key !== "name"){
                if(info[key]){
                    info[key] += item[key]
                } else {
                    info[key] = item[key]
                }
            }
        }
    })
    return info
}

function q (resistance) {
    if(resistance < 0) {
        return 1 - resistance/200
    } else if (resistance >=0 && resistance < 75){
        return 1 - resistance/100
    } else {
        return 1/(1+resistance/100*4)
    }
}

function df(youLv=0, eLv=0, td){
    return (100+youLv)/(100+youLv+(100+eLv)*(td? (100-td)/100 : 1))
}

// 固定攻击力 19  防御力23 生命值299 5.3% 
function calc_clips_normal (n) {
    let clips = [
        {
            精通: 23,
            attRate: 5.8,
            criticalRate: 3.9,
            criticalStrike:7.8
        },
        {
            精通:23,
            attRate: 5.8,
            criticalRate: 3.9,
            criticalStrike:7.8
        },
        {
            精通:23,
            fixedAtt: 19,
            criticalRate: 3.9,
            criticalStrike:7.8
        },
        {
            精通:23,
            attRate: 5.8,
            criticalRate: 3.9,
            criticalStrike:7.8
        },
        {
            精通:23,
            attRate: 5.8,
            criticalRate:n!=2? 0:3.9,
            criticalStrike:n!=2? 7.8:0
        }
    ]
    let data = {}
    clips.forEach(item => {
        for (const key in item) {
            data[key] = data[key]? (data[key]+item[key]) : item[key]
        }
    })
    return data
}

function jt(k){
    return Math.log(0.99316499 + 0.00209988607 * k + 0.0000001213236971*k*k)
}